class LocalCache {
  // 插入一条缓存
  setCache(key: string, value: any) {
    window.localStorage.setItem(key, JSON.stringify(value));
  }

  //   通过key获取对应缓存
  getCache(key: string) {
    const value = window.localStorage.getItem(key);
    if (value) {
      return JSON.parse(value);
    }
  }

  // 删除某条缓存
  deleteCache(key: string) {
    window.localStorage.removeItem(key);
  }

  //   清除所有缓存
  clearCache(code: number) {
    if (code == 123456) {
      window.localStorage.clear();
    }
  }
}

export default new LocalCache();
